<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var a = 1;
        var b = 2;

        function fun() {
            //字母c没有加var 关键字 所以他为全局变量
            c = 3;
            var b = 4;
            b++;
            c++;
        }
        fun();
        console.log(b); //2
        //在函数的外部是可以访问变量c的
        console.log(c); //4
    </script>
</body>

</html>